<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GitHub文件加速</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
        
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }
        
        /* 移动设备样式 */
        @media (max-width: 640px) {
            body {
                background: white;
                padding: 0;
                align-items: flex-start;
            }
            
            .card {
                backdrop-filter: none;
                background: transparent;
                box-shadow: none;
                border: none;
                padding: 1rem;
            }
            
            .container {
                max-width: 100%;
            }
        }
        
        /* 桌面设备保留原有卡片样式 */
        @media (min-width: 641px) {
            .card {
                backdrop-filter: blur(10px);
                background: rgba(255, 255, 255, 0.85);
                box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
                border-radius: 16px;
                border: 1px solid rgba(255, 255, 255, 0.18);
            }
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            transition: all 0.3s ease;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(118, 75, 162, 0.3);
        }
        
        .btn-secondary {
            transition: all 0.3s ease;
        }
        
        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
        }
        
        .input-field:focus {
            border-color: #764ba2;
            box-shadow: 0 0 0 2px rgba(118, 75, 162, 0.2);
        }
        
        .animate-pulse {
            animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
    </style>
</head>
<body class="min-h-screen flex items-center justify-center p-4">
    <div class="container mx-auto max-w-2xl">
        <div class="card p-8">
            <div class="text-center mb-8">
                <i class="fas fa-bolt text-4xl mb-4 text-purple-600 animate-pulse"></i>
                <h1 class="text-3xl font-bold text-gray-800 mb-2">GitHub文件加速</h1>
                <p class="text-gray-500">快速获取GitHub文件的加速链接</p>
            </div>
            
            <div class="mb-6">
                <label for="github-url" class="block text-sm font-medium text-gray-700 mb-2">
                    <i class="fas fa-link mr-2"></i>GitHub链接
                </label>
                <div class="flex space-x-2">
                    <input 
                        type="text" 
                        id="github-url" 
                        placeholder="粘贴GitHub文件或release链接..." 
                        class="input-field flex-1 px-4 py-3 border border-gray-200 rounded-lg focus:ring-2 focus:ring-purple-200 focus:border-purple-500"
                    >
                    <button 
                        onclick="downloadFile()" 
                        class="btn-primary text-white px-6 py-3 rounded-lg font-medium"
                    >
                        <i class="fas fa-download mr-2"></i>下载
                    </button>
                </div>
            </div>

            <div class="bg-purple-50 p-6 rounded-xl mb-8">
                <h2 class="font-bold text-purple-800 mb-3 flex items-center">
                    <i class="fas fa-info-circle mr-2"></i>使用说明
                </h2>
                <ul class="text-sm text-purple-700 space-y-2">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                        <span>支持release、archive以及文件加速</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                        <span>release/archive使用Cloudflare加速</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                        <span>文件会跳转至JsDelivr</span>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                        <span>不支持项目文件夹</span>
                    </li>
                </ul>
            </div>

            <div class="grid grid-cols-2 gap-4">
                <button 
                    onclick="setExample('branch-source')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-code-branch mr-2"></i>分支源码示例
                </button>
                <button 
                    onclick="setExample('release-source')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-tag mr-2"></i>release源码示例
                </button>
                <button 
                    onclick="setExample('release-file')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-file-archive mr-2"></i>release文件示例
                </button>
                <button 
                    onclick="setExample('branch-file')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-file-code mr-2"></i>分支文件示例
                </button>
                <button 
                    onclick="setExample('commit-file')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-hashtag mr-2"></i>commit文件示例
                </button>
                <button 
                    onclick="setExample('gist-file')" 
                    class="btn-secondary px-4 py-3 rounded-lg text-sm flex items-center justify-center"
                >
                    <i class="fas fa-code mr-2"></i>Gist文件示例
                </button>
            </div>
            
            <div class="mt-8 text-center">
                <a href="https://github.com/hunshcn/gh-proxy" 
                   target="_blank" 
                   class="inline-flex items-center px-4 py-2 rounded-lg bg-gray-100 hover:bg-gray-200 text-gray-700 transition-colors">
                    <i class="fab fa-github text-lg mr-2"></i>
                    <span>本项目开源仓库</span>
                </a>
            </div>
        </div>
    </div>

    <script>
        function downloadFile() {
            const inputUrl = document.getElementById('github-url').value.trim();
            let downloadUrl = '';
            
            if (!inputUrl) {
                alert('请输入GitHub链接');
                return;
            }

            // 处理各种GitHub链接
            if (inputUrl.includes('releases/download/')) {
                // release文件
                const match = inputUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/releases\/download\/([^\/]+)\/(.+)/);
                if (match) {
                    downloadUrl = `https://github.luyb.dpdns.org/https://github.com/${match[1]}/${match[2]}/releases/download/${match[3]}/${match[4]}`;
                }
            } else if (inputUrl.includes('/archive/')) {
                // 分支或release源码
                const match = inputUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/archive\/(.+)/);
                if (match) {
                    downloadUrl = `https://github.luyb.dpdns.org/https://github/${match[1]}/${match[2]}/archive/${match[3]}`;
                }
            } else if (inputUrl.includes('/blob/')) {
                // 分支或commit文件
                const match = inputUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)/);
                if (match) {
                    downloadUrl = `https://cdn.jsdelivr.net/gh/${match[1]}/${match[2]}@${match[3]}/${match[4]}`;
                }
            } else if (inputUrl.includes('gist.githubusercontent.com')) {
                // gist文件
                downloadUrl = inputUrl.replace('gist.githubusercontent.com', 'gist.hunsh.cn');
            }

            if (downloadUrl) {
                // 创建隐藏的下载链接并触发点击
                const a = document.createElement('a');
                a.href = downloadUrl;
                a.download = downloadUrl.split('/').pop();
                a.style.display = 'none';
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            } else {
                alert('不支持的GitHub链接格式');
            }
        }

        // 保留setExample函数不变
        function setExample(type) {
            const examples = {
                'branch-source': 'https://github.com/hunshcn/project/archive/master.zip',
                'release-source': 'https://github.com/hunshcn/project/archive/v0.1.0.tar.gz',
                'release-file': 'https://github.com/hunshcn/project/releases/download/v0.1.0/example.zip',
                'branch-file': 'https://github.com/hunshcn/project/blob/master/filename',
                'commit-file': 'https://github.com/hunshcn/project/blob/1111111111111111111111111111/filename',
                'gist-file': 'https://gist.githubusercontent.com/cielpy/351557e6e465c12986419ac5a4dd2568/raw/cmd.py'
            };
            
            document.getElementById('github-url').value = examples[type];
        }
    </script>
</body>
</html>